package com.ego.controller;

import com.ego.pojo.Specification;
import com.ego.service.SpecService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Ares
 * @date 2020-11-25
 */
@RestController
@RequestMapping("/spec")
public class SpecController {
    @Resource
    private SpecService specService;

    @GetMapping("/{cid}")
    public ResponseEntity<String> getSpecByCid(@PathVariable Long cid){
        Specification specification = specService.selectSpecByCid(cid);
        if(specification!=null){
            return ResponseEntity.ok(specification.getSpecifications());
        }
        return ResponseEntity.status(500).build();
    }

    @PostMapping
    public ResponseEntity<Void> saveSpec(Specification specification){
        specService.insertSpec(specification);
        return ResponseEntity.ok().build();
    }

    @PutMapping
    public ResponseEntity<Void> updateSpec(Specification specification){
        specService.updateSpec(specification);
        return ResponseEntity.ok().build();
    }
}
